package com.unicom.priceboard.data.vo;

import java.util.HashMap;

import com.unicom.priceboard.util.NumberUtil;


public class HaIndex {
	public static final int HANOI_CENTER = 2;

    private String session;
    private String indexDate;
    private String totalTrade;
    private String totalTradeFormat="";
    private String changeIndexFormat="";
    private double index;
    private String indexFormat="";
    private double changeIndex; //the change in index
    private double pctIndex;  //percent change index
    private String pctIndexFormat;
    private int centerId;
    private String totalVol;
    private long totalVal;
    private long ptTotalVol;
    private long ptTotalVal;
    private String css = "";
    private String indicator = "";
    private String numberSign = "";
    private String outputMarketValue = "";
    private String marketState = "";
    private long advances;
    private long declines;
    private long noChange;
    private String time;
    private int marketStatus;

    private HashMap<String,String> mapCSS = new HashMap<String, String>();
    private HashMap<String,String> mapIndicator = new HashMap<String, String>();

    public HaIndex() {
    	mapCSS.put("up", "index_up");
    	mapCSS.put("down", "index_down");
    	mapCSS.put("unchange", "index_unchange");

    	mapIndicator.put("up", "images/up.gif");
    	mapIndicator.put("down", "images/down.gif");
    	mapIndicator.put("unchange", "");
    }

	/**
	 * @return the change value
	 */
	public double getChangeIndex() {
		return changeIndex;
	}
	/**
	 * @param change the change to set
	 */
	public void setChangeIndex(double changeIndex) {
		if(changeIndex!=0)
			this.changeIndexFormat = String.valueOf(changeIndex);
		else
			this.changeIndexFormat = "";

		this.changeIndex = changeIndex;

		String key = changeIndex>0?"up":(changeIndex<0?"down":"unchange");
		this.numberSign = key.equals("up")?"+":(key.equals("down")?"-":"");
		this.css = mapCSS.get(key);
		this.indicator = mapIndicator.get(key);
	}

	public double getPctIndex() {
		return pctIndex;
	}
	/**
	 * @param change the change to set
	 */
	public void setPctIndex(double pctIndex) {
		this.pctIndex = pctIndex;
		if(pctIndex<0){
			this.pctIndexFormat="("+String.valueOf(pctIndex)+"%)";
		}else if(pctIndex>0){
			this.pctIndexFormat="(+"+String.valueOf(pctIndex)+"%)";
		}else if(pctIndex==0){
			this.pctIndexFormat="";
		}
	}
	/**
	 * @return the changed
	 */
	public int getCenterId() {
		return centerId;
	}
	/**
	 * @param changed the changed to set
	 */
	public void setCenterId(int centerId) {
		this.centerId = centerId;
	}
	/**
	 * @return the session
	 */
	public String getSession() {
		return session;
	}
	/**
	 * @param session the session to set
	 */
	public void setSession(String session) {
		this.session = session;
	}
	/**
	 * @return the totalTrade
	 */
	public String getTotalTrade() {
		return totalTrade;
	}
	/**
	 * @param totalTrade the totalTrade to set
	 */
	public void setTotalTrade(String totalTrade) {
			this.totalTrade = totalTrade;
			this.totalTradeFormat=NumberUtil.formatTotalTrade(totalTrade);

	}
	/**
	 * @return the val
	 */
	public long getTotalVal() {
		return totalVal;
	}
	/**
	 * @param val the val to set
	 */
	public void setTotalVal(long val) {
		this.totalVal = val;
		if(val>0){
			this.setOutputMarketValue(NumberUtil.formatHose_MarketValue(val));
		}
	}
	/**
	 * @return the vn_Index
	 */
	public double getIndex() {
		return index;
	}
	/**
	 * @param vn_Index the vn_Index to set
	 */
	public void setIndex(double index) {
		if(index!=0)
			this.indexFormat=String.valueOf(index);
		else
			this.indexFormat="";
		this.index = index;
	}
	/**
	 * @return the vnIndex_date
	 */
	public String getIndexDate() {
		return this.indexDate;
	}

	/**
	 * @return date in format dd/mm/yyyy
	 */
	public String getDisplayIndexDate()
	{
		/*-- Change date's format from yyyy-mm-dd to dd/mm/yyyy --*/
		String[] arrDay = indexDate.split("-");
		String retVal = arrDay[2]+"/"+arrDay[1]+"/"+arrDay[0];

		return retVal;
	}

	/**
	 * @param vnIndex_date the vnIndex_date to set
	 */
	public void setIndexDate(String indexDate) {

		this.indexDate = indexDate;
	}
	/**
	 * @return the vol
	 */
	public String getTotalVol() {
		return totalVol;
	}
	/**
	 * @param vol the vol to set
	 */
	public void setTotalVol(String vol) {
		if(vol.equals("0")||vol.equals("0.0")){
			this.totalVol="";
		}
		else this.totalVol = vol;
	}

	public long getPtTotalVol() {
		return ptTotalVol;
	}

	public long getVol() {
		return Long.valueOf(this.totalVol.replaceAll(",","")) - this.ptTotalVol;
	}

	public long getVal() {
		return this.totalVal - this.ptTotalVal;
	}

	/**
	 * @param vol the vol to set
	 */
	public void setPtTotalVol(long vol) {
		this.ptTotalVol = vol;
	}

	public long getPtTotalVal() {
		return ptTotalVal;
	}
	/**
	 * @param vol the vol to set
	 */
	public void setPtTotalVal(long val) {
		this.ptTotalVal = val;
	}

	public void setToPreviousDay(String today) {
		this.setTotalTrade("0");
		this.setPtTotalVal(0);
		this.setPtTotalVol(0);
		this.setTotalVal(0);
		this.setTotalVol("0");
	}

	/**
	 * @return the css
	 */
	public String getCss() {
		return css;
	}

	/**
	 * @return the indicator
	 */
	public String getIndicator() {
		return indicator;
	}

	/**
	 * @return the sign
	 */
	public String getNumberSign() {
		return numberSign;
	}

	/**
	 * @param sign the sign to set
	 */
	public void setNumberSign(String sign) {
		this.numberSign = sign;
	}

	/**
	 * @return the outputMarketValue
	 */
	public String getOutputMarketValue() {
		return outputMarketValue;
	}

	/**
	 * @param outputMarketValue the outputMarketValue to set
	 */
	public void setOutputMarketValue(String outputMarketValue) {
		this.outputMarketValue = outputMarketValue;
	}

	@Override
	public boolean equals(Object obj) {
		if(!this.getClass().isInstance(obj)) {
			return false;
		}else {
			HaIndex compareObj = (HaIndex) obj;
			if(this.index!=compareObj.getIndex()) {
				return false;
			}else if(!this.totalVol.equals(compareObj.getTotalVol())) {
				return false;
			}else if(!this.getOutputMarketValue().equals(compareObj.getOutputMarketValue())) {
				return false;
			}else if(!this.getSession().equals(compareObj.getSession())) {
				return false;
			}
		}

		return true;
	}

	/**
	 * @return the marketState
	 */
	public String getMarketState() {
		return marketState;
	}

	/**
	 * @param marketState the marketState to set
	 */
	public void setMarketState(String marketState) {
		this.marketState = marketState;
	}

	public String getPctIndexFormat() {
		return pctIndexFormat;
	}

	public void setPctIndexFormat(String pctIndexFormat) {
		this.pctIndexFormat = pctIndexFormat;
	}

	public String getChangeIndexFormat() {
		return changeIndexFormat;
	}

	public void setChangeIndexFormat(String changeIndexFormat) {
		this.changeIndexFormat = changeIndexFormat;
	}

	public String getIndexFormat() {
		return indexFormat;
	}

	public void setIndexFormat(String indexFormat) {
		this.indexFormat = indexFormat;
	}

	public String getTotalTradeFormat() {
		return totalTradeFormat;
	}

	public void setTotalTradeFormat(String totalTradeFormat) {
		this.totalTradeFormat = totalTradeFormat;
	}

	public long getAdvances() {
		return advances;
	}

	public void setAdvances(long advances) {
		this.advances = advances;
	}

	public long getDeclines() {
		return declines;
	}

	public void setDeclines(long declines) {
		this.declines = declines;
	}

	public long getNoChange() {
		return noChange;
	}

	public void setNoChange(long noChange) {
		this.noChange = noChange;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public int getMarketStatus() {
		return marketStatus;
	}

	public void setMarketStatus(int marketStatus) {
		this.marketStatus = marketStatus;
	}
}
